<template>
    <div class="">
        <el-dialog
                :title="title"
                :visible.sync="dialogFormVisible"
                width="600px"
                :close-on-click-modal="false"
                @close="close"
        >
            <el-table :data="gridData">
                <el-table-column property="date" label="边长(cm)" width="150"></el-table-column>
                <el-table-column property="name" label="建议扫码距离(m)" width="200"></el-table-column>
                <el-table-column label="普通二维码">
                    <template slot-scope="scope">
                        <div><a :href="scope.row.load"> <i class="el-icon-download iconadd fon_16 curs"></i></a></div>
                    </template>
                </el-table-column>
            </el-table>
            <div slot="footer" class="dialog-footer">
                <el-button size="medium" @click="close">取 消</el-button>
                <el-button size="medium" type="primary" @click="save">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    import {establishCode} from "@/api/instore";

    export default {
        name: "meteriaSave",
        created() {
        },
        data() {
            return {
                form: {
                    id: '',
                    num: '',
                },
                gridData: [{
                    date: '12cm',
                    name: '0.8m',
                    load: ''
                }, {
                    date: '15cm',
                    name: '1m',
                    load: ''
                }, {
                    date: '30cm',
                    name: '1.5m',
                    load: ''
                }, {
                    date: '50cm',
                    name: '2m',
                    load: ''
                }],
                title: "",
                dialogFormVisible: false,
            }
        },
        components: {},
        methods: {
            showEdit(row) {
                if (!row) {
                    this.title = "二维码下载";
                } else {
                    this.title = "二维码下载";
                    this.getSaveTable(row.id)
                    // this.form = Object.assign({}, row);
                }
                this.dialogFormVisible = true;
            },
            // async getSaveTable(id) {
            //     const {data} = await getSaveTable({id,});
            //     this.form = Object.assign({}, data);
            // },
            close() {
                this.$refs["form"].resetFields();
                this.form = this.$options.data().form;
                this.dialogFormVisible = false;
            },
            save() {
                this.$refs["form"].validate(async (valid) => {
                    if (valid) {
                        const {msg} = await establishCode(this.form);
                        this.$baseMessage(msg, "success");
                        this.$emit("fetchData");
                        this.close();
                    } else {
                        return false;
                    }
                });
            },
        }
    };
</script>
